# -*- coding: utf-8 -*-

from sqlalchemy import create_engine, Column, String, Integer
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

base = declarative_base()
class User(base):
    __tablename__ = 'user'
    id = Column(Integer, primary_key=True,autoincrement=True)
    name = Column(String(20))



engine = create_engine('sqlite:////home/jiangzx/project/class_visual/test.db')
DBsession = sessionmaker(bind=engine)

base.metadata.create_all(engine)



session = DBsession()

#增
new_user = User(name='test2')
session.add(new_user)
#删
session.query(User).filter(User.id == 2).delete()
#改
session.query(User).filter(User.id == 3).update({User.name: "update_test"})
session.commit()
#查
people = session.query(User).all()
for item in people:
    print(item.id)
    print(item.name)
session.close()